package com.ruoyi.log.domain;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * mangoDB聚合查询
 */
@Data
public class AggregationQuery implements Serializable {

    private static final String YEAR = "Y";

    /**
     * 表名
     */
    private String collectionName;

    /**
     * 检索条件 keys values
     * 不允许查所有 keys长度不能小于1
     */
    private String[] keys;
    private String[] values;

    /**
     * $in
     */
    private String inKey;
    private List<String> inValues;

    public void in(String column ,List<String> coll){
        this.inValues = coll;
        this.inKey = column;
    }

    /**
     * key时间格式化后groupBy
     */
    private String formatDateKey;
    private String formatExpression;
    public static AggregationQuery dateFomatGoupBy(String column , String formatExpression , String groupKey){
        AggregationQuery aggregationQuery = new AggregationQuery();
        aggregationQuery.setFormatDateKey(column);
        aggregationQuery.setGroupKey(groupKey);
        aggregationQuery.setFormatExpression(formatExpression);
        return aggregationQuery;
    }


    /**
     * 分组检索
     */
    private String groupKey;

    /**
     * 检索范围
     */
    private String scopeKey;
    private String startValue;
    private String endValue;

    /**
     * 是否统计
     */
    private Boolean count;

    public AggregationQuery() {

    }

    public AggregationQuery(String[] keys, String[] values,String scopeKey,String startValue,String endValue) {
        this.values = values;
        this.keys = keys;
        this.scopeKey = scopeKey;
        this.startValue = startValue;
        this.endValue = endValue;
    }

    /**
     * 分组
     */
    public AggregationQuery(String[] keys, String[] values, String groupKey) {
        this.groupKey = groupKey;
        this.groupKey = groupKey;
        this.values = values;
        this.keys = keys;
    }

    /**
     * 范围检索
     */
    public AggregationQuery(String collectionName, String[] keys, String[] values, String scopeKey, String startValue, String endValue, boolean count) {
        this.collectionName = collectionName;
        this.scopeKey = scopeKey;
        this.startValue = startValue;
        this.endValue = endValue;
        this.values = values;
        this.keys = keys;
        this.count = count;
    }


}
